package com.le.tester.book.effectivejava3rdchinese.articletwo;

/**
 * createTime：2022/7/28 10:53
 * description：builder pattern
 */
public class NutritionFacts {

    private final int servingSize;

    private final int servings;

    private final int calories;

    public static class Builder {

        private final int servingSize;

        private final int servings;

        private int calories = 0;

        public Builder(int servingSize, int servings) {
            this.servingSize = servingSize;
            this.servings = servings;
        }

        public Builder calories(int calories) {
            this.calories = calories;
            return this;
        }

        public NutritionFacts build() {
            return new NutritionFacts(this);
        }
    }

    private NutritionFacts(Builder builder) {

        servingSize = builder.servingSize;
        servings = builder.servings;
        calories = builder.calories;
    }

    public static void main(String[] args) {
        NutritionFacts build = new Builder(1, 2).calories(3).build();

    }

}
